from pathlib import Path
from shutil import rmtree
def delete(f:Path):
    if f.is_file():
        f.unlink()
    elif f.is_dir():
        rmtree(f)
def clean_d(dpath: Path):
    for f in dpath.iterdir():
        name = f.name
        rm_ends = {'.xlsx', '.rar', '.log', '.png', '.bat', '.yml', '.csv', '.jar', '~','.py','.jpg','.jpeg','.json',
                   '.html'}
        rm_contains = {'(1)','(2)','-master','BarCheck-'}
        if any(name.endswith(ext) for ext in rm_ends):
            delete(f)
        elif any(ct in name for ct in rm_contains):
            delete(f)
        else:
            print(f)


dpath = Path(r'D:\dl')
clean_d(dpath)
